package com.sirap.spring.boot.demo.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sirap.basic.component.Extractor;
import com.sirap.basic.json.MistUtil;
import com.sirap.basic.thirdparty.ServletHelper;
import com.sirap.basic.tool.D;
import com.sirap.basic.util.StrUtil;
import com.sirap.spring.boot.demo.config.FishContextUtils;

@ResponseBody
@Controller
@RequestMapping(value = "/x")
public class XController {
	
	@RequestMapping(value = "/detail", method = RequestMethod.GET)
	public Object actuatorInfo(HttpServletRequest request) {
		String port = FishContextUtils.getProperty("management.server.port");
		String home = ServletHelper.getHomeUrl(request);
		String portInfo = "";
		if(StrUtil.isRegexMatched("\\d+", port)) {
			portInfo = ":" + port;
		}
		String aurl = home + portInfo + "/actuator";
		D.pla(port, portInfo, aurl);
		Extractor<Object> frank = new Extractor<Object>() {
    		
			@Override
			public String getUrl() {
				showFetching();
				return aurl;
			}
			
			@Override
			protected void parse() {
				item = MistUtil.ofJsonText(source);
			}
		};
		
		Object obj = frank.process().getItem();
		
		return obj;
	}
}
